package com.woniuxy.ams.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.ams.entity.*;
import com.woniuxy.ams.service.CheckinfoService;
import com.woniuxy.ams.service.ExamineListService;
import com.woniuxy.ams.service.ExaminelistCheckinfoService;
import com.woniuxy.ams.service.UserService;
import com.woniuxy.ams.utils.SystemUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author susunxi
 * @version 1.0
 * @date 2021/12/15 10:04
 */
@RequestMapping("checkInfo")
@RestController
public class CheckInfoController {

    CheckinfoService checkinfoService;
    UserService userService;
    ExamineListService examineListService;
    ExaminelistCheckinfoService examinelistCheckinfoService;

    @Autowired
    public void setCheckinfoService(CheckinfoService checkinfoService) {
        this.checkinfoService = checkinfoService;
    }

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    @Autowired
    public void setExamineListService(ExamineListService examineListService) {
        this.examineListService = examineListService;
    }

    @Autowired
    public void setExaminelistCheckinfoService(ExaminelistCheckinfoService examinelistCheckinfoService) {
        this.examinelistCheckinfoService = examinelistCheckinfoService;
    }



    /**
     * 根据用户的信息，显示该用户应该审核的信息
     * @param pageRequest 传入的信息
     * @return 返回所以的待审核信息
     */
    @RequestMapping("showAllPending")
    public ResultEntity<?> showAllPending(@RequestBody PageRequest<CheckInfoShowData> pageRequest) {
        User user = SystemUtils.getLoginUser();

        CheckInfoShowData data = pageRequest.getData();
        data.setCheckInfoId(user.getId());

        PageHelper.startPage(pageRequest.getCurrentPage(),pageRequest.getLimit());
        List<CheckInfoShowData> examineLists = checkinfoService.getAllPending(data);
        PageInfo<CheckInfoShowData> checkInfoShowDataPageInfo = new PageInfo<>(examineLists);
        return new ResultEntity<>(200, "您的待审核信息如下", checkInfoShowDataPageInfo);
    }


    /**
     * 进行打分，审核用户
     * @param rater 前端传人的对象
     * @return 返回影响的行数
     */
    @PostMapping("checkUser")
    public ResultEntity<?> checkUsers(@RequestBody Rater rater) {
        int status = examineListService.updateScroe(rater);
        return new ResultEntity<>(200,"打分成功",status);
    }

    /**
     * 查询用户上传的自评表
     * @param checkInfoShowData 根据用户信息查询
     * @return 返回自评表内容
     */
    @RequestMapping("getPath")
    public ResultEntity<?> findPath(@RequestBody CheckInfoShowData checkInfoShowData){
        User user = SystemUtils.getLoginUser();
        checkInfoShowData.setUid(user.getId());
        SelfAppraisal path=checkinfoService.getPath(checkInfoShowData);
        return new ResultEntity<>(200,"路径如下",path);
    }



}
